/************************************************************************

								Heroes IV
					  Copyright 2001, The 3DO Company

	------------------------------------------------------------------
  						 obelisk_marker.cpp


	$Header: $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "obelisk_marker.h"

#include "adv_object_type.h"
#include "adventure_map.h"
#include "object_registration.h"

namespace
{
	int const k_current_map_format_version = 1;
	int const k_current_save_format_version = 0;

	t_object_registration<t_adv_obelisk_marker> k_registration( k_adv_object_obelisk_marker );
}

// -------------------------------------------------------------------
// Read from save game
// -------------------------------------------------------------------
bool t_obelisk_marker::read( std::streambuf & stream )
{
	int version = ::get< t_uint16 >( stream );

	if ( version < 0 || version > k_current_save_format_version )
		return false;

	m_location.row =	::get< t_uint32 >( stream );
	m_location.column = ::get< t_uint32 >( stream );
	m_location.level =	::get< t_uint8  >( stream );
	m_radius =			::get< t_uint16 >( stream );

	return true;
}

// -------------------------------------------------------------------
// Write to save game
// -------------------------------------------------------------------
bool t_obelisk_marker::write( std::streambuf & stream ) const
{
	::put< t_uint16 >( stream, k_current_save_format_version );

	::put< t_uint32 >( stream, m_location.row );
	::put< t_uint32 >( stream, m_location.column );
	::put< t_uint8  >( stream, m_location.level );
	::put< t_uint16 >( stream, m_radius );

	return true;
}

// -------------------------------------------------------------------
// Read from editor map
// -------------------------------------------------------------------
bool t_adv_obelisk_marker::read_from_map( std::streambuf& buffer, t_progress_handler* )
{
	int version = get< t_uint16 >( buffer );
	if ( version < 0 || version > k_current_map_format_version )
		return false;

	if ( version > 0 )
	{
		m_radius = get< t_uint16 >( buffer );
	}
	else
	{
		m_radius = 0;
	}

	return true;
}

// -------------------------------------------------------------------
// Place on map.
// Markers are never actually placed on map; we just add their data
// to the map's obelisk information.
// -------------------------------------------------------------------
void t_adv_obelisk_marker::place( t_adventure_map& map, t_adv_map_point const& point )
{
	map.add_obelisk_marker( get_color(), t_obelisk_marker( point, m_radius ) );
}

